<!doctype html>
<html lang="`en`">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>

<div id="app">
    <h3>单个复选框</h3>
    <input type="checkbox" id="agreement" @change="changeSelect" :checked="isAgree">  <label for="agreement">{{isAgree}}</label>
    <p v-for="(item,index) in items"><input type="checkbox" @change="childrenSelect" v-model="item.checked">{{item.name}}</p>
</div>

<script src="js/vue.global.js"></script>
<script>
    var vm = Vue.createApp({
        data() {
            return {
                isAgree: false,
                items:[
                    {id:1,checked:true,name:"ok"},
                    {id:2,checked:false,name:"ok"},
                    {id:3,checked:true,name:"ok"},
                    {id:4,checked:true,name:"ok"}
                ]
            }
        },
        methods:{
            changeSelect(){
                this.isAgree = !this.isAgree;
                this.items.map(item=>item.checked = this.isAgree);
            },
            childrenSelect(){
                var newarr = this.items.filter(item=>item.checked);
                this.isAgree = newarr.length == this.items.length;
            }
        }
    }).mount("#app");
</script>

</body>
</html>